package com.cloud.drore.eboss.operation.mapper.provider;

import com.cloud.drore.eboos.common.constant.CommonConstant;
import com.cloud.drore.eboos.common.entity.supplier.ProductRelation;
import com.cloud.drore.eboss.operation.entity.po.OTAGetProductRequest;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/3/12 10:39 <br>
 * @Author: <a href="1451173193@qq.com">杨亮</a>
 */
public class FactoryGetProductProvider {
    public String validateDistributorSql(Long disId) {
        String sql = "select case merchant_state when '" + CommonConstant.MERCHANT_AUDIT_ALREADY + "' then 'OK' else 'NO' end isOk \n" +
                " from eboos_merchant where merchant_type='MERCHANT_DISTRIBUTE' and id=" + disId;
        return sql;
    }

    public String getProductInfoSingleSql(OTAGetProductRequest reqpo) {
        //ticket
        StringBuffer sql = new StringBuffer("");
        if (CommonConstant.TYPE_OF_TICKET.equals(reqpo.getProductType())) {
            sql.append("select b.product_num,e.poi_name,e.area_address_city city,b.product_name,b.payment_type,a.book_advance_day,a.book_advance_time,a.use_advance_hour,a.auto_cancel_time,a.book_person_type,\n" +
                    "a.visit_person_required_for_quantity,a.valid_type,a.days_after_use_date_valid,a.use_date,a.market_price,c.sales_price sellPrice,a.instruction,a.can_refund,a.can_overdue_refund,\n" +
                    "a.refund_apply_time_before_valid_end_day,a.refund_charge,a.refund_charge_type,a.refund_info,a.sms_templet,a.e_ticket_type\n" +
                    "  from eboos_ticket a INNER JOIN eboos_product b on (a.common_product_id =b.id)\n" +
                    "INNER JOIN eboos_distributor_product_association c on c.main_id=b.id\n" +
                    "INNER JOIN eboos_product_consume_relation d on b.id=d.product_id\n" +
                    "INNER JOIN eboos_poi e on d.poi_id=e.id\n" +
                    "where b.status='"+CommonConstant.THE_SHELVES+"' and  c.distributor_id="+reqpo.getDistributorId()+" and" +
                    " b.product_num='"+reqpo.getProductNum()+"' and b.product_type='"+CommonConstant.TYPE_OF_TICKET+"'\n");
            //组合产品
        } else if (CommonConstant.TYPE_OF_COMBINATION.equals(reqpo.getProductType())) {
            sql.append("select b.product_num,b.product_name,b.payment_type,b.instruction,a.sales_price sellPrice from eboos_distributor_product_association a INNER JOIN eboos_product b on a.main_id=b.id\n" +
                    "where b.status='THE_SHELVES' and a.distributor_id="+reqpo.getDistributorId()+" " +
                    " and b.product_num='"+reqpo.getProductNum()+"' and b.product_type='"+CommonConstant.TYPE_OF_COMBINATION+"'\n");
        } else {
            sql.append("select null");
        }

        return sql.toString();
    }

    public String getProductInfoAllSql(OTAGetProductRequest reqpo) {
        //ticket
        StringBuffer sql = new StringBuffer("");
        if (CommonConstant.TYPE_OF_TICKET.equals(reqpo.getProductType())) {
            sql.append("select b.product_num,e.poi_name,e.area_address_city city,b.product_name,b.payment_type,a.book_advance_day,a.book_advance_time,a.use_advance_hour,a.auto_cancel_time,a.book_person_type,\n" +
                    "a.visit_person_required_for_quantity,a.valid_type,a.days_after_use_date_valid,a.use_date,a.market_price,c.sales_price sellPrice,a.instruction,a.can_refund,a.can_overdue_refund,\n" +
                    "a.refund_apply_time_before_valid_end_day,a.refund_charge,a.refund_charge_type,a.refund_info,a.sms_templet,a.e_ticket_type\n" +
                    "  from eboos_ticket a INNER JOIN eboos_product b on (a.common_product_id =b.id)\n" +
                    "INNER JOIN eboos_distributor_product_association c on c.main_id=b.id\n" +
                    "INNER JOIN eboos_product_consume_relation d on b.id=d.product_id\n" +
                    "INNER JOIN eboos_poi e on d.poi_id=e.id\n" +
                    "where b.status='"+CommonConstant.THE_SHELVES+"' and  c.distributor_id="+reqpo.getDistributorId()+" and b.product_type='"+CommonConstant.TYPE_OF_TICKET+"' \n");
            //组合产品
        } else if (CommonConstant.TYPE_OF_COMBINATION.equals(reqpo.getProductType())) {
            sql.append("select b.product_num,b.product_name,b.payment_type,b.instruction,a.sales_price sellPrice from eboos_distributor_product_association a INNER JOIN eboos_product b on a.main_id=b.id\n" +
                    "where b.status='THE_SHELVES' and a.distributor_id="+reqpo.getDistributorId()+" and b.product_type='"+CommonConstant.TYPE_OF_COMBINATION+"' \n");
        } else {
            sql.append("select null");
        }

        return sql.toString();
    }

    public String getProductIdByNumSql(ProductRelation product){
        StringBuffer sql=new StringBuffer("");
        sql.append("select id product_id from eboos_product where product_num='"+product.getProductNum()+"'");
        return sql.toString();
    }
}
